/** @var array Map of (mem,real,cpu) */
protected $end;
/** @var array List of resolved profile calls with start/end data */
- protected $stack = array();
+ protected $stack = [];
/** @var array Queue of open profile calls with start data */
- protected $workStack = array();
+ protected $workStack = [];
/** @var array Map of (function name => aggregate data array) */
- protected $collated = array();
+ protected $collated = [];
/** @var bool */
protected $collateDone = false;
protected $collateOnly = true;
/** @var array Cache of a standard broken collation entry */
protected $errorEntry;
- /** @var callable Cache of a profile out callback */
- protected $profileOutCallback;
/**
* @param array $params
*/
- public function __construct( array $params = array() ) {
+ public function __construct( array $params = [] ) {
$this->errorEntry = $this->getErrorEntry();
$this->collateOnly = empty( $params['trace'] );
- $this->profileOutCallback = function ( $profiler, $section ) {
- $profiler->profileOutInternal( $section );
- };
}
/**
* @return array List of method entries arrays, each having:
* - name : method name
* - calls : the number of invoking calls
- * - real : real time ellapsed (ms)
+ * - real : real time elapsed (ms)
* - %real : percent real time
- * - cpu : real time ellapsed (ms)
+ * - cpu : real time elapsed (ms)
* - %cpu : percent real time
* - memory : memory used (bytes)
* - %memory : percent memory used
$totalReal = max( $this->end['real'] - $this->start['real'], 0 );
$totalMem = max( $this->end['memory'] - $this->start['memory'], 0 );
- $profile = array();
+ $profile = [];
foreach ( $this->collated as $fname => $data ) {
- $profile[] = array(
+ $profile[] = [
'name' => $fname,
'calls' => $data['count'],
'real' => $data['real'] * 1000,
'%memory' => $totalMem ? 100 * $data['memory'] / $totalMem : 0,
'min_real' => 1000 * $data['min_real'],
'max_real' => 1000 * $data['max_real']
- );
+ ];
}
- $profile[] = array(
+ $profile[] = [
'name' => '-total',
'calls' => 1,
'real' => 1000 * $totalReal,
'%memory' => 100,
'min_real' => 1000 * $totalReal,
'max_real' => 1000 * $totalReal
- );
+ ];
return $profile;
}
public function reset() {
$this->start = null;
$this->end = null;
- $this->stack = array();
- $this->workStack = array();
- $this->collated = array();
+ $this->stack = [];
+ $this->workStack = [];
+ $this->collated = [];
$this->collateDone = false;
}
* @return array Initial collation entry
*/
protected function getZeroEntry() {
- return array(
+ return [
'cpu' => 0.0,
'real' => 0.0,
'memory' => 0,
'count' => 0,
'min_real' => 0.0,
'max_real' => 0.0
- );
+ ];
}
/**
$memory = memory_get_usage();
if ( $this->start === null ) {
- $this->start = array( 'cpu' => $cpu, 'real' => $real, 'memory' => $memory );
+ $this->start = [ 'cpu' => $cpu, 'real' => $real, 'memory' => $memory ];
}
- $this->workStack[] = array(
+ $this->workStack[] = [
$functionname,
count( $this->workStack ),
$real,
$cpu,
$memory
- );
+ ];
}
/**
if ( $this->collateOnly ) {
$this->collated[$message] = $this->errorEntry;
} else {
- $this->stack[] = array( $message, 0, 0.0, 0.0, 0, 0.0, 0.0, 0 );
+ $this->stack[] = [ $message, 0, 0.0, 0.0, 0, 0.0, 0.0, 0 ];
}
$functionname = $ofname;
} elseif ( $ofname !== $functionname ) {
if ( $this->collateOnly ) {
$this->collated[$message] = $this->errorEntry;
} else {
- $this->stack[] = array( $message, 0, 0.0, 0.0, 0, 0.0, 0.0, 0 );
+ $this->stack[] = [ $message, 0, 0.0, 0.0, 0, 0.0, 0.0, 0 ];
}
}
$memchange = $memUsage - $omem;
$this->updateEntry( $functionname, $elapsedcpu, $elapsedreal, $memchange );
} else {
- $this->stack[] = array_merge( $item, array( $realTime, $cpuTime, $memUsage ) );
+ $this->stack[] = array_merge( $item, [ $realTime, $cpuTime, $memUsage ] );
}
- $this->end = array(
+ $this->end = [
'cpu' => $cpuTime,
'real' => $realTime,
'memory' => $memUsage
- );
+ ];
}
/**
throw new Exception( "Tree is only available for trace profiling." );
}
return implode( '', array_map(
- array( $this, 'getCallTreeLine' ), $this->remapCallTree( $this->stack )
+ [ $this, 'getCallTreeLine' ], $this->remapCallTree( $this->stack )
) );
}
if ( count( $stack ) < 2 ) {
return $stack;
}
- $outputs = array();
+ $outputs = [];
for ( $max = count( $stack ) - 1; $max > 0; ) {
/* Find all items under this entry */
$level = $stack[$max][1];
- $working = array();
+ $working = [];
for ( $i = $max -1; $i >= 0; $i-- ) {
if ( $stack[$i][1] > $level ) {
$working[] = $stack[$i];
}
}
$working = $this->remapCallTree( array_reverse( $working ) );
- $output = array();
+ $output = [];
foreach ( $working as $item ) {
array_push( $output, $item );
}
array_unshift( $outputs, $output );
}
- $final = array();
+ $final = [];
foreach ( $outputs as $output ) {
foreach ( $output as $item ) {
$final[] = $item;
return; // already collated as methods exited
}
- $this->collated = array();
+ $this->collated = [];
# Estimate profiling overhead
$oldEnd = $this->end;
$this->calculateOverhead( $profileCount );
# First, subtract the overhead!
- $overheadTotal = $overheadMemory = $overheadInternal = array();
+ $overheadTotal = $overheadMemory = $overheadInternal = [];
foreach ( $this->stack as $entry ) {
// $entry is (name,pos,rtime0,cputime0,mem0,rtime1,cputime1,mem1)
$fname = $entry[0];